<?php
class TemporadasController extends AppController {

	var $name = 'Temporadas';

	function index() {
		$this->Temporada->recursive = 0;
		$this->set('temporadas', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid temporada', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('temporada', $this->Temporada->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Temporada->create();
			if ($this->Temporada->save($this->data)) {
				$this->Session->setFlash(__('The temporada has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The temporada could not be saved. Please, try again.', true));
			}
		}
		$series = $this->Temporada->Series->find('list', array('fields'=>array('id_series', 'nome')));
		$estados = $this->Temporada->Estados->find('list', array('fields'=>array('id_estados','estados')));
		$lugares = $this->Temporada->Lugares->find('list', array('fields'=>array('id_lugares','lugares')));
		$this->set(compact('series', 'estados', 'lugares'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid temporada', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Temporada->save($this->data)) {
				$this->Session->setFlash(__('The temporada has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The temporada could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Temporada->read(null, $id);
		}
		$series = $this->Temporada->Series->find('list', array('fields'=>array('id_series', 'nome')));
		$estados = $this->Temporada->Estados->find('list', array('fields'=>array('id_estados','estados')));
		$lugares = $this->Temporada->Lugares->find('list', array('fields'=>array('id_lugares','lugares')));
		$this->set(compact('series', 'estados', 'lugares'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for temporada', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Temporada->delete($id)) {
			$this->Session->setFlash(__('Temporada deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Temporada was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>